# Created by brokenq on 2015/10/9.
'use strict'

module.exports = angular.module 'lib.directives.yh-permission', []
.directive 'yhPermit', ($log, $rootScope)->
  $log.log "yh permit directive init"
  return {
    restrict: "A"
    link: (scope, elem, attrs, ctrl)->
      permissions = $rootScope.session.permissions
      code = attrs.yhPermit
      for permission in permissions
        if permission.code is code
          $(elem).show()
          return
      $(elem).hide()
  }
#.directive 'yhNoPermit', ($log, $rootScope)->
#  $log.log "yh permit directive init"
#  return {
#    restrict: "A"
#    link: (scope, elem, attrs, ctrl)->
#      role = $rootScope.session.user.role
#      noPermissions = eval attrs.yhNoPermit
#      if noPermissions.indexOf(role) != -1 then $(elem).hide() else $(elem).show()
#  }